﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace VeryCodes.Common.DEncrypt
{
    /// <summary>
    /// Hash加解密类
    /// </summary>
    public class HashEncode
    {
        /// <summary>
        /// Gets the random value.
        /// </summary>
        /// <returns></returns>
        public string GetRandomValue()
        {
            Random random = new Random();
            return random.Next(1, 0x7fffffff).ToString();
        }

        /// <summary>
        /// Gets the security.
        /// </summary>
        /// <returns></returns>
        public string GetSecurity()
        {
            return HashEncoding(GetRandomValue());
        }

        /// <summary>
        /// Hashes the encoding.
        /// </summary>
        /// <param name="Security">The security.</param>
        /// <returns></returns>
        public string HashEncoding(string Security)
        {
            byte[] bytes = new UnicodeEncoding().GetBytes(Security);
            byte[] buffer = new SHA512Managed().ComputeHash(bytes);
            Security = "";
            foreach (byte num in buffer)
            {
                Security = Security + ((int)num) + "O";
            }
            return Security;
        }
    }
}

